<?php
session_start();
include("load-settings.php");

if(!isset($_SESSION['user']))
	header("Location: login.php");

$user = mysql_real_escape_string($_SESSION['user']);
$result = mysql_query("SELECT * FROM user WHERE id = $user");
$row = mysql_fetch_array($result);

if($row['type'] != 2 && $row['type'] != 3)
	header("Location: home.php");

$page = $_POST['page'];
$per_page = $_POST['per_page'];
$start = ($page-1) * $per_page;

$result = mysql_query("SELECT * FROM account_order ORDER BY timestamp DESC LIMIT $start, $per_page") or die(mysql_error());

while($row = mysql_fetch_array($result))
{
	$user_result = mysql_query("SELECT * FROM user WHERE id = ".$row['user']);
	$user_row = mysql_fetch_array($user_result);

	$account_result = mysql_query("SELECT * FROM bulk_account WHERE order_id = ".$row['id']);
	$account_row = mysql_fetch_array($account_result);

	if($account_row['referrals'] == 0)
	{
		$subresult = mysql_query("SELECT * FROM option_list WHERE name = 'Level 30 Account price'");
		$subrow = mysql_fetch_array($subresult);
		$price = $subrow['value'];
	}
	else if($account_row['referrals'] == 50)
	{
		$subresult = mysql_query("SELECT * FROM option_list WHERE name = '50 Referral account price'");
		$subrow = mysql_fetch_array($subresult);
		$price = $subrow['value'];
	}
	else if($account_row['referrals'] == 100)
	{
		$subresult = mysql_query("SELECT * FROM option_list WHERE name = '100 Referral account price'");
		$subrow = mysql_fetch_array($subresult);
		$price = $subrow['value'];
	}

	echo "<tr><td>".$row['id']."</td>";
	echo "<td>".date("d M Y", $row['timestamp'])."</td>";
	echo "<td>".$user_row['paypal']."</td>";
	echo "<td>".$account_row['username']."</td>";
	echo "<td>".$account_row['password']."</td>";
	echo "<td>".$account_row['region']."</td>";
	echo "<td>".$price."</td>";
	echo "</tr>";
}
?>